package com.wenan.ui.controls.dateChooser
{
	
	import mx.controls.DateChooser;
	import mx.core.mx_internal;
	import mx.events.FlexEvent;

	public class YearPanel extends DateChooserExt
	{
		private var grid:YearGrid = new YearGrid();
		
		public function YearPanel()
		{
			super();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			this.removeChild(this.mx_internal::dateGrid);
			this.mx_internal::fwdMonthButton.visible = false;
			this.mx_internal::backMonthButton.visible = false;
			this.mx_internal::upYearButton.addEventListener(FlexEvent.BUTTON_DOWN,
				upYearButton_buttonDownHandler);
			this.mx_internal::downYearButton.addEventListener(FlexEvent.BUTTON_DOWN,
				downYearButton_buttonDownHandler);
			grid.addEventListener(DateEvent.SELECTEDDATE, selectedDateHandler);
			grid.y = 38;
			grid.x = 6;
			grid.percentWidth = 100;
			grid.percentHeight = 100;
			this.addChild(grid);
		}
		
		private function upYearButton_buttonDownHandler(event:FlexEvent):void
		{
			grid.upHandler();
		}
		
		private function downYearButton_buttonDownHandler(event:FlexEvent):void
		{
			grid.downHandler();
		}
		
		private function selectedDateHandler(event:DateEvent):void
		{
			this.mx_internal::yearDisplay.text = event.date.toString();
			this.mx_internal::monthDisplay.text = "";
			dispatchEvent(new DateEvent(DateEvent.SELECTEDDATE, event.date));
		}
		
		override protected function updateDisplayList(unscaledWidth:Number,
													  unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			var yearDisplay:String = grid.row11._label.text;
			this.mx_internal::yearDisplay.text = ("" == yearDisplay ? (new Date).fullYear : yearDisplay);
			this.mx_internal::monthDisplay.text = "";
		}
		
		override public  function set selectedDate(value:Date):void
		{
			var curr:int = value.fullYear;
			grid.selectedDate = curr;
			grid.dispatchEvent(new DateEvent(DateEvent.SELECTEDDATE, curr.toString()));
		}
	}
}